package com.middle.common.validate;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class EnumByteValidate implements ConstraintValidator<EnumByte, Byte> {

	private byte[] values;

	@Override
	public void initialize(EnumByte constraintAnnotation) {
		ConstraintValidator.super.initialize(constraintAnnotation);
		values = constraintAnnotation.values();
	}

	@Override
	public boolean isValid(Byte value, ConstraintValidatorContext context) {
		if (value != null) {
			byte newValue = value.byteValue();
			for (byte enumByte : values) {
				if (newValue == enumByte) {
					return true;
				}
			}
		}
		return false;
	}

}
